package org.anderground.editor.gui.properties.tunnel;

import java.util.List;

import org.anderground.core.model.Station;
import org.anderground.core.model.Tunnel;
import org.anderground.editor.gui.properties.AbstractPropertiesPanel;

@SuppressWarnings("serial")
public class TunnelPropertiesPanel extends AbstractPropertiesPanel<Tunnel> {

	public static final int NO_SORT = 0;
	public static final int FROM_STATION_SORT = 1;
	public static final int TO_STATION_SORT = 2;
	private Tunnel[] tunnels;

	public TunnelPropertiesPanel() {
		super(new TunnelFromStationNameProperty(),
				new TunnelToStationNameProperty(), new TunnelTimeProperty(),
				new TunnelSmoothProperty(), new TunnelLineProperty());
	}

	public void setSelection(Tunnel[] tunnels) {
		this.tunnels = tunnels;

		this.updateView();
	}

	@Override
	public void onSelectionChanged(List<Station> selectedStations,
			List<Tunnel> selectedTunnels) {
		if (selectedTunnels != null && !selectedTunnels.isEmpty()) {
			setSelection(selectedTunnels.toArray(new Tunnel[0]));
		}

	}

	@Override
	protected int getRowCount() {
		return (tunnels == null) ? 0 : tunnels.length;
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		return (tunnels == null || rowIndex < 0 || rowIndex >= tunnels.length) ? null
				: tunnels[rowIndex];
	}

}
